package com.sample.api;

import java.io.File;
import java.io.IOException;

import org.springframework.core.io.Resource;

import com.swak.App;
import com.swak.annotation.Get;
import com.swak.annotation.RestService;
import com.swak.vertx.transport.multipart.MultipartFile;
import com.swak.vertx.transport.multipart.PlainFile;

/**
 * 描述
 * 
 * @author Auto Generator
 * @date 2022-04-21T20:47:07.509267200
 */
@RestService(path = "/api/swak/file", value = "swakFileApi")
public class FileApi {

	/**
	 * 通过 zero copy 的方式输出文本
	 *
	 * @return Result
	 * @throws IOException yichang
	 */
	@Get("/zerocopy")
	public PlainFile zeroCopy() throws IOException {
		Resource resource = App.resource("/com/sample/api/bigtext.html");
		File file = resource.getFile();
		return PlainFile.of(file);
	}

	/**
	 * 通过 zero copy 的方式输出文本
	 *
	 * @return Result
	 * @throws IOException yichang
	 */
	@Get("/zerocopy2")
	public PlainFile zeroCopy(String diskFile) {
		File file = new File(diskFile);
		return PlainFile.of(file);
	}

	/**
	 * 通过 zero copy 的方式输出文本
	 *
	 * @return Result
	 * @throws IOException yichang
	 */
	@Get("/download")
	public MultipartFile zeroCopy2() throws IOException {
		Resource resource = App.resource("/com/sample/api/bigtext.html");
		File file = resource.getFile();
		return MultipartFile.of(file).name("文件下载.html");
	}
}
